
Forked from slug and added some pull requests and options.
Slugifies every string, even when it contains unicode!
Make strings url-safe.
- respecting RFC 3986
- Comprehensive tests
- No dependencies (except the unicode table)
- Not in coffee-script (except the tests lol)
- Coerces foreign symbols to their english equivalent
- Works in browser (window.slug) and AMD/CommonJS-flavoured module loaders (except the unicode symbols unless you use browserify but who wants to download a ~2mb js file, right?)
npm install larvitslugify
Examples
var slug = require('larvitslugify'),
print = console.log.bind(console, '>')
print(slug('i ♥ unicode'))
print(slug('unicode ♥ is ☢'))
print(slug('i ♥ unicode', '_'))
slug.charmap['♥'] = 'freaking love'
print(slug('I ♥ UNICODE'))
print(slug('☏-Number', {lower: true}))
print(slug('i <3 unicode'))
Options
slug('string', [{options} || 'replacement']);
All options
slug('string', {
'replacement': '-',
'symbols': true,
'remove': /[d]/g,
'lower': true,
'charmap': {'Ä': 'ae'},
'multicharmap': {'ð': 'oi'},
'save': ['*', 'ð'],
'wordLimit': 5
});
Option modes
slug.defaults.mode ='pretty';
slug.defaults.modes['rfc3986'] = {
'replacement': '-',
'symbols': true,
'remove': null,
'lower': true,
'charmap': slug.charmap,
'multicharmap': slug.multicharmap
};
slug.defaults.modes['pretty'] = {
'replacement': '-',
'symbols': true,
'remove': /[.]/g,
'lower': false,
'charmap': slug.charmap,
'multicharmap': slug.multicharmap
};
Browser
When using browserify you might want to remove the symbols table from your bundle by using --ignore
similar to this:
browserify slug.js --ignore unicode/category/So -s slug > slug-browser.js
When using webpack you can use:
externals: {
'unicode/category/So': '{}',
}
In your webpack config to replace the require with an empty object stub.